//
//  F_MaybeYouLike_ViewController.swift
//  MyFood
//
//  Created by dllo on 16/2/21.
//  Copyright © 2016年 XRG. All rights reserved.
//

import UIKit
import SwiftyJSON

class F_MaybeYouLike_ViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource, F_Userlike_TableViewCellDelegate {

    var userLikeArr : Array<F_UserLike_Model> = []
    var tableView : UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        createView()
        createData()

        // Do any additional setup after loading the view.
    }

    func createView(){

        self.tableView = UITableView(frame: CGRectMake(0, 0, BASE_WIDTH, BASE_HEIGHT), style: UITableViewStyle.Plain)
        self.view.addSubview(self.tableView)

        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.rowHeight = 240
        self.tableView.registerNib(UINib(nibName: "F_Userlike_TableViewCell", bundle: nil), forCellReuseIdentifier: "cell")

    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.userLikeArr.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell : F_Userlike_TableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as! F_Userlike_TableViewCell
        
        let bigModel = self.userLikeArr[indexPath.row]
        cell.img.sd_setImageWithURL(NSURL(string: bigModel.image))
    cell.btn1.setTitle(bigModel.myTags[0].text, forState: UIControlState.Normal)
        cell.btn2.setTitle(bigModel.myTags[1].text, forState: UIControlState.Normal)
        cell.btn3.setTitle(bigModel.myTags[2].text, forState: UIControlState.Normal)
        cell.btn4.setTitle(bigModel.myTags[3].text, forState: UIControlState.Normal)
        cell.btn5.setTitle(bigModel.myTags[4].text, forState: UIControlState.Normal)

        cell.selectionStyle = UITableViewCellSelectionStyle.None
        cell.delegate = self
        cell.rowNum = indexPath.row
        return cell
    }


    func createData(){

        XRAFNetworkTool.POSTUrl(BASE_URL, body: "page=1&methodName=UserLikes&size=20&version=4.3.1&", requestBodyStyle: XRRequestStyle.String, headFile: nil, response: XRResponseStyle.XRJSON, success: { (task, result) -> Void in

            let json = JSON(result)
            let arr = json["data"]["data"].array

            for temp in arr!{
                let dic : Dictionary = temp.dictionaryObject!
                let userModel = F_UserLike_Model(dic:dic)
                for tags_infoDic in userModel.tags_info{
                    let model = F_Tagsinfo_Model(dic:tags_infoDic)
                    userModel.myTags.append(model)
                }
                self.userLikeArr.append(userModel)
            }

            if self.userLikeArr.count != 0{
                self.tableView.reloadData()
            }
            }) { (task, error) -> Void in
                print(error)
        }
    }


    func clickUserLikeMovie(num: Int) {
        let model = self.userLikeArr[num]
        print("播放地址是\(model.video)   +   \(model.video1)")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
